package com.shenyong.ladmin.service.Impl;

import com.shenyong.ladmin.mapper.ArticleMapper;
import com.shenyong.ladmin.entity.Article;
import com.shenyong.ladmin.result.Page;
import com.shenyong.ladmin.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Create By:qiang
 * Date: 2019/11/28 18:06
 * 文件说明: ArticleServiceImpl
 */
@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public List<Article> listArticle(Page page) {
        List<Article> list = new ArrayList<Article>();
        for (Article am : articleMapper.listArticle(page)) {
            am.setArticle_publishDate(am.getArticle_publishDate().substring(0, 19));
            if (am.getArticle_editTime() != null && am.getArticle_editTime() != "")
                am.setArticle_editTime(am.getArticle_editTime().substring(0, 19));
            list.add(am);
        }
        return list;
    }

    @Override
    public int getArticleCount(Page page) {
        return articleMapper.getArticleCount(page);
    }

    @Override
    public int deleteArricle(int article_id) {
        return articleMapper.deleteArricle(article_id);
    }

    @Override
    public List<Article> selectArticle(Article article) {
        return articleMapper.selectArticle(article);
    }

    @Override
    public List<Article> selectArticleTop5() {
        return articleMapper.selectArticleTop5();
    }
    @Override
    public List<Article> AllArticle(Article article) {
        return articleMapper.AllArticle(article);
    }

}
